<?php
namespace app\admin\controller;

use app\common\controller\Admin;
use app\common\model\User as UserModel;
class User extends Admin
{
    
    public function login(){
    
    }

    /**
     * 查- 列表
     * @return string
     */
    public function index(){


        return $this->fetch();


    }

    public function filter(){

        $pararms = paramFromPost();

        $filter = array();


        //性别
        if(isset($pararms['sex'])){
            $filter['sex'] =$pararms['sex'];
        }

        //名称
        if(isset($pararms['nickname'])){
            $filter['nickname'] = ['like','%'.$pararms['nickname'].'%'];
        }


        //注册时间
        if(isset($pararms['start_time'])){

            $startTime = strtotime($pararms['start_time']);
            if(!isset($startTime)){
                error('开始时间格式错误');
            }

            if($pararms['end_time']){

                $endTime = strtotime($pararms['end_time'])+86400;
                if(!isset($endTime)){
                    error('截止时间格式错误');
                }

            }else{
                $endTime = time();//如果不传就是截止到今天
            }

            $filter['create_time'] = array(array('EGT',$startTime),array('ELT',$endTime),'and');

        }


        $query = UserModel::where($filter)->order('id desc');
        $list = $query->paginate(20);


        success($list->toArray());

    }


}